const app = Vue.createApp({
    data() {
        return {
            message: "hello world",
            isStart: false,
            questions: [],
            question: '',
            num: 0,
            isShow: false,
            dialogVisible: false
        }
    },
    methods: {
        init() {
            axios({
                url: '/getAllQuestions',
                method: "GET"
            }).then((res) => {
                console.log(res.data);
                this.questions = res.data
                this.num = this.questions.length
            })
        },
        // 题目滚动，
        getOne() {
            this.index = this.rand(this.num)
            this.question = this.questions[this.index]
        },
        rand(num) {
            return Math.floor(Math.random() * num)
        },
        start() {
            this.isStart = true
            this.timer = setInterval(() => {
                this.getOne()
            }, 50)
            this.outTimer = setTimeout(() => {
                console.log("here");
                this.isStart = false
                clearInterval(this.timer)
                if (!this.question) {
                    this.getOne()
                }
                this.dialogVisible = true
            }, 3000)
        },
        confirm() {
            this.dialogVisible = false
            this.isShow = false
            this.questions.splice(this.index, 1)
        },
        handleClose(done) {
            const _this = this
            this.$confirm('确认关闭？')
                .then((_) => {
                    done()
                    _this.isShow = false
                    _this.questions.splice(_this.index, 1)
                })
                .catch((_) => {})
        },
    },
    updated() {
        this.num = this.questions.length
    },
    mounted() {
        this.init()
    }
})
app.use(ElementPlus);
app.mount("#view")